package com.example.mapping.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import com.example.mapping.common.core.ResultResponse;
import com.example.mapping.dto.FlowModelQueryDto;
import com.example.mapping.manage.FlowModelManage;
import com.example.mapping.dto.FlowModelDto;
import com.example.mapping.vo.FlowModelVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 流程controller类
 *
 * @author baoyoujia
 */
@RestController
@RequestMapping("/flow_model")
public class FlowModelController {

    @Autowired
    private FlowModelManage flowModelManage;

    @PostMapping("/list")
    public ResultResponse<PageDTO<FlowModelVo>> getFlowByPage(@RequestBody FlowModelQueryDto flowModelQueryDto) {
        return ResultResponse.buildSuccess(flowModelManage.getFlowByPage(flowModelQueryDto));
    }

    @GetMapping("/{id}")
    public ResultResponse<FlowModelVo> get(@PathVariable("id") Long id) {
        return ResultResponse.buildSuccess(flowModelManage.getFlow(id));
    }

    @PostMapping("/flow")
    public ResultResponse<Boolean> add(@RequestBody FlowModelDto flowModelDto) {
        return ResultResponse.buildSuccess(flowModelManage.addFlow(flowModelDto));
    }

    @PutMapping("/{id}")
    public ResultResponse<Boolean> edit(@PathVariable("id") Long id, @RequestBody FlowModelDto flowModelDto) {
        flowModelDto.setId(id);
        return ResultResponse.buildSuccess(flowModelManage.editFlow(flowModelDto));
    }

    @DeleteMapping("/{id}")
    public ResultResponse<Boolean> del(@PathVariable("id") Long id) {
        return ResultResponse.buildSuccess(flowModelManage.delFlow(id));
    }

}
